package kernel

import (
	"area"
	"region/config"
	"util/log"
)

type Region struct {
	RegionId int32
	cfg      *config.Config
	mapinfo  *area.MapInfo
	kernel   *Kernel
	runchan  chan bool
}

//初始化所有数据
func (r *Region) initAllInfo() {
	r.kernel = CreateKernel(r.RegionId)
}

func (r *Region) Start(ch chan bool, c *config.Config, regionid int32) {
	r.RegionId = regionid
	r.cfg = c
	r.runchan = make(chan bool)
	r.initAllInfo()
	r.run()
}

func (r *Region) run() {

wait:
	for {
		select {
		case <-r.runchan:
			break wait
		}
	}

	log.TraceInfo("region", "service quit")

}

func (r *Region) shutdown() {

	r.kernel.Shutdown()

	r.runchan <- true
}
